// 1.3
// 生成设备UUID，配合get_device_token接口使用
use uuid::Uuid;
use crate::db::{db_insert::db_insert, db_select::db_select};

#[derive(Debug)]
pub struct UUID{
    pub uuid_device_id: String,
    pub uuid_serial_number: String,
}

pub async fn get_uuid() ->UUID {
    
    let mut uuid_structure = UUID {
        uuid_device_id: String::new(),
        uuid_serial_number: String::new(),
    };

    if let Ok(config) = db_select("uuid_device_id").await {
        uuid_structure.uuid_device_id = config.value;
    } else {
        uuid_structure.uuid_device_id = Uuid::new_v4().to_string();
        db_insert("uuid_device_id", &uuid_structure.uuid_device_id).await.unwrap();
    }
    if let Ok(config) = db_select("uuid_serial_number").await {
        uuid_structure.uuid_serial_number = config.value;
    } else {
        uuid_structure.uuid_serial_number = Uuid::new_v4().to_string();
        db_insert("uuid_serial_number", &uuid_structure.uuid_serial_number).await.unwrap();
    }
    return uuid_structure;
}